package com.xiaojiu;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;

import com.xiaojiu.bean.AdModel;
import com.xiaojiu.util.AppConfig;
import com.xiaojiu.util.StringUtils;
import com.xiaojiu.widget.MyAdViewPager;

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends AppCompatActivity {
    private MyAdViewPager vPager;
    private List<AdModel> mAds;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        vPager = (MyAdViewPager) findViewById(R.id.viewpager);

        /**
         * 获取屏幕分辨率
         */
        DisplayMetrics metric = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metric);
        AppConfig.getInstance().putInt(AppConfig.ScreenWidth, metric.widthPixels);
        AppConfig.getInstance().putInt(AppConfig.ScreenHight, metric.heightPixels);

        mAds = new ArrayList<>();
        mAds.add(new AdModel(""));
        mAds.add(new AdModel(""));
        mAds.add(new AdModel(""));
        getAd();

    }

    private void getAd() {
        /**
         * 根据图片的长和宽，自适应手机，不变形
         */
        vPager.onInit(StringUtils.getDynamicHeight(720, 360));
        vPager.setData(mAds);
    }
    @Override
    protected void onResume() {
        super.onResume();
        vPager.startLoop();
    }

    @Override
    protected void onPause() {
        super.onPause();
        vPager.stopLoop();
    }
}
